﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MadeInPortugal;
using MadeInPortugal.Class;
using System.Data;
using System.IO;
using System.Collections;

namespace MadeInPortugalWebApplication.WebControl
{
    public partial class DisplayProductWC : System.Web.UI.UserControl
    {
        int productId;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["Id"] != null)
                {
                    try
                    {
                        //int.TryParse(Request.QueryString["Id"], out productId);
                        fillproduct(int.Parse(Request.QueryString["Id"]));
                        
                    }
                    catch (Exception)
                    {
                        Response.Redirect("index.aspx");
                    }
                    
                }
                else
                { Response.Redirect("index.aspx"); }
            }
        }

        private void fillproduct(int productId)
        {
            Product prod = new Product();
            prod = prod.GetById(productId);
            lblMinReq.Text = prod.MinReq.ToString();
            lblName.Text = prod.ProductName;
            lblPrice.Text = prod.Price.ToString();
            lblSpecification.Text = prod.Specifications;
            lblTag.Text = prod.Tag.TagName;
            lblType.Text = prod.Tag.Type[0].Type;
            imgLogo.ImageUrl = HttpContext.Current.Request.Url.Host.ToString() + "\\style\\img\\smallIcons\\" + prod.Enterprise.Id.ToString() + ".image";
            cbxProperties.Items.Clear();
            foreach (ProdProperties item in prod.Properties)
            {
                cbxProperties.Items.Add(new ListItem(item.PropertyName, item.PropertyId.ToString(), false));
                cbxProperties.Items.FindByValue(item.PropertyId.ToString()).Selected = (bool)item.Property;
            }

            ImageUploaded.ImageUrl = HttpContext.Current.Request.Url.Host.ToString() + "\\style\\img\\bigIcons\\" + prod.Id.ToString() + ".image";
            Session["Product"] = prod;

        }

        protected void btnEmail_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/email.aspx");
        }
    }
}


